package com.platform.modules.cpt.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.common.utils.Query;
import com.platform.common.utils.StringUtils;
import com.platform.modules.cpt.dao.CptAcceptanceDao;
import com.platform.modules.cpt.dao.CptAcceptanceTeamDao;
import com.platform.modules.cpt.entity.CptAcceptanceEntity;
import com.platform.modules.cpt.entity.CptAcceptanceTeamEntity;
import com.platform.modules.cpt.service.CptAcceptanceService;
import com.platform.modules.cpt.service.CptAcceptanceTeamService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CptAcceptanceTeamServiceImpl extends ServiceImpl<CptAcceptanceTeamDao, CptAcceptanceTeamEntity> implements CptAcceptanceTeamService {

    private static final Logger logger = LoggerFactory.getLogger(CptAcceptanceTeamServiceImpl.class);

    @Override
    public boolean save(CptAcceptanceTeamEntity entity) {
        if(StringUtils.isBlank(entity.getId())) {
            this.baseMapper.insert(entity);
        }else {
            this.baseMapper.updateById(entity);
        }
        return true;
    }

    @Override
    public Page<CptAcceptanceTeamEntity> queryPage(Map<String, Object> params) {
        Page<CptAcceptanceTeamEntity> page = new Query<CptAcceptanceTeamEntity>(params).getPage();
        List<CptAcceptanceTeamEntity> list = baseMapper.selectList(page, params);
        return page.setRecords(list);
    }

    @Override
    public CptAcceptanceTeamEntity queryOne(Map<String, Object> params) {
        List<CptAcceptanceTeamEntity> list = baseMapper.selectList(params);
        if(list==null || list.isEmpty()){
            return null;
        }else if(list.size()==1){
            return list.get(0);
        }else {
            //list.size() > 1
            return null;
        }
    }

    @Override
    public List<CptAcceptanceTeamEntity> queryList(Map<String, Object> params) {
        return baseMapper.selectList(params);
    }

}
